import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { CompanyQuery, CompanyPageResult, CompanyForm } from "./types";

/**
 * 获取公司分页
 *
 * @param queryParams
 */
export function getCompanyPage(
  queryParams?: CompanyQuery
): AxiosPromise<CompanyPageResult> {
  return request({
    url: "/api/v1/company/page",
    method: "get",
    params: queryParams,
  });
}

/**
 * 修改公司
 * @param companyId 公司ID
 * @param data 公司数据
 * @returns
 */
export function updateCompany(
  companyId: number,
  data: CompanyForm
): AxiosPromise<any> {
  return request({
    url: "/api/v1/company/" + companyId,
    method: "put",
    data: data,
  });
}

/**
 * 创建公司
 * @param data 公司数据
 * @returns
 */
export function addCompany(data: CompanyForm): AxiosPromise<any> {
  return request({
    url: "/api/v1/company",
    method: "post",
    data: data,
  });
}

/**
 * 初始化密码
 * @param companyId 公司ID
 * @returns
 */
export function resetPassword(companyId: number): AxiosPromise<any> {
  return request({
    url: "/api/v1/company/resetPassword/" + companyId,
    method: "put",
  });
}

/**
 * 获取公司详情
 * @param companyId 公司ID
 * @returns
 */
export function getCompanyForm(companyId: number): AxiosPromise<CompanyForm> {
  return request({
    url: "/api/v1/company/" + companyId,
    method: "get",
  });
}
